/**
 * Created by Asura on 2016/2/3.
 */
'use strict';

const a = 10;

//a = 2;//TypeError: Assignment to constant variable.

//const b;//SyntaxError: Unexpected token ;必须初始化

//对象冻结，c既不能指向别的，c的内容也不允许改变，c里的const const
const c = Object.freeze({});
//c.value = "123";//TypeError: Can't add property value, object is not extensible

const d = Object.freeze({
    "value": "123",
    "obj": {
        "value": "hello"
    }
});
d.obj.value = "comeon";//可以改变，冻结对象只是冻结当前对象
//完全冻结对象
function constantize(obj) {
    Object.freeze(obj);
    Object.keys(d).forEach(function (value, index) {
        if (typeof obj[value] === 'object') {
            constantize(obj[value]);
        }
    });
}
constantize(d);
//完全冻结后不能再访问对象
//d.obj.value = "i want back";//TypeError: Cannot assign to read only property 'value' of #<Object>
console.log(JSON.stringify(d));

global.g = 1;//全局对象，node里是global,浏览器里是window
console.log(g);
let f = 12;
console.log(global.f);//undefined